package com.spic.system.controller;

import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.system.domain.SysAnnounceReader;
import com.spic.system.domain.vo.SysAnnounceReaderVo;
import com.spic.system.service.ISysAnnounceReaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 阅读人Controller
 *
 * @author spic
 * @date 2022-06-15
 */
@RestController
@RequestMapping("/announceReader")
public class SysAnnounceReaderController extends BaseController
{
    @Autowired
    private ISysAnnounceReaderService sysAnnounceReaderService;

    /**
     * 查询阅读列表
     */
    @GetMapping("/announceReaderList")
    public TableDataInfo selectSysAnnounceReaderListByUserId(SysAnnounceReaderVo sysAnnounceReaderVo)
    {
        startPage();
        List<SysAnnounceReaderVo> list = sysAnnounceReaderService.selectSysAnnounceReaderListByUserId(sysAnnounceReaderVo);
        return getDataTable(list);
    }


    /**
     * 修改阅读人
     */
//    @PreAuthorize(hasPermi = "system:reader:edit")
    @Log(title = "阅读人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAnnounceReader sysAnnounceReader)
    {
        return toAjax(sysAnnounceReaderService.updateSysAnnounceReader(sysAnnounceReader));
    }


    //更新是否过期 不显示了
    @PostMapping("/setStateHidden")
    public AjaxResult  setStateHidden (){
        sysAnnounceReaderService.updateSysAnnounceReaderByStateHidden();
        return AjaxResult.success();
    }

    //根据公示公告类型查询 和当前用户查询  列表 传：  obj.type

    @GetMapping("/getAnnounceReaderByTypeList")
    public  AjaxResult getAnnounceReaderByTypeList(SysAnnounceReaderVo sysAnnounceReaderVo){
        List<SysAnnounceReaderVo> list = sysAnnounceReaderService.getAnnounceReaderByTypeList(sysAnnounceReaderVo);
        return AjaxResult.success(list);
    }
    // 查询 当前用户下 类型为安全公示类别的 部门级和矿级 数据并聚合

    @GetMapping("/getAnnounceReaderBySafetyList")
    public  AjaxResult getAnnounceReaderBySafetyList(){
        List<SysAnnounceReaderVo> list = sysAnnounceReaderService.getAnnounceReaderBySafetyList();
        return AjaxResult.success(list);
    }

    /**
     * 获取阅读人详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAnnounceReaderService.selectSysAnnounceReaderById(id));
    }
}
